import fs from '@ohos.file.fs';
import window from '@ohos.window';
import db from '../common/core/db';
import utils from '../common/core/utils';
import logger from '../common/core/logger';
import current from '../common/core/current';
import UIAbility from '@ohos.app.ability.UIAbility';
import cardManager from '../common/manager/cardManager';
import downloadManager from '../common/manager/downloadManager';

export default class EntryAbility extends UIAbility {
  async onCreate() {
    globalThis.abilityContext = this.context;
    globalThis.filesDir = this.context.filesDir;
    logger.init(this.context.filesDir);
    let hapDir = `${this.context.filesDir}/haps`;
    fs.mkdir(hapDir);
    globalThis.hapDir = hapDir;
    cardManager.createRdbStore(this.context);
  }

  onWindowStageCreate(windowStage: window.WindowStage) {
    utils.setLayoutFullScreen(windowStage, utils.COLOR_WHITE, utils.COLOR_BLACK, utils.COLOR_LIKE_WHITE, utils.COLOR_BLACK);
    db.createInstance(this.context);
    downloadManager.createInstance(this.context);
    current.instance.loadInfo();
    globalThis.windowStage = windowStage;
    windowStage.loadContent('pages/Index');
  }
}